package com.grf.es.transport;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.xcontent.XContentFactory;

/**
 * @author 郭荣锋
 * 修改文档
 */
public class Update {

	/**
	 * 更新索引
	 * @throws IOException
	 * @throws InterruptedException
	 * @throws ExecutionException
	 */
	public void update() throws IOException, InterruptedException, ExecutionException {
		Index index = new Index();
		TransportClient client = index.getClient();
		UpdateRequest updateRequest = new UpdateRequest("blog3", "article", "2"); 
		updateRequest.doc(XContentFactory.jsonBuilder().startObject()
				.field("id","2")
				.field("title","hello")
				.field("content","6666"));
		UpdateResponse response = client.update(updateRequest).get();
		System.out.println(response.getResult());
	}
	
	
	
	public static void main(String[] args) throws IOException, InterruptedException, Exception {
		Update u = new Update();
		u.update();
	}
	
}
